package com.chunayev.numerology.gui.table.listener;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.chunayev.numerology.gui.table.NameCalculationsTable;
import com.chunayev.numerology.gui.table.NumerologicTable;


/**
 * @author Sergey Chunayev
 */
public class TokensTableSelectionListener implements ListSelectionListener {
    
    private NumerologicTable numerologicTable;
    
    private NameCalculationsTable tokensStatisticsTable;
    
    /**
     * @return the numerologicTable
     */
    public NumerologicTable getNumerologicTable() {
        return this.numerologicTable;
    }
    
    /**
     * @return the tokensStatisticsTable
     */
    public NameCalculationsTable getTokensStatisticsTable() {
        return this.tokensStatisticsTable;
    }
    
    /**
     * @param numerologicTable
     *            the numerologicTable to set
     */
    public void setNumerologicTable(final NumerologicTable numerologicTable) {
        this.numerologicTable = numerologicTable;
    }
    
    /**
     * @param tokensStatisticsTable
     *            the tokensStatisticsTable to set
     */
    public void setTokensStatisticsTable(
            final NameCalculationsTable tokensStatisticsTable) {
        this.tokensStatisticsTable = tokensStatisticsTable;
    }
    
    /*
     * (non-Javadoc)
     * @see
     * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event
     * .ListSelectionEvent)
     */
    @Override
    public void valueChanged(final ListSelectionEvent e) {
        final int index = tokensStatisticsTable.getSelectedRow();
        if (index != -1) {
            final int otherPosition = tokensStatisticsTable
                    .<Integer> getGenericValueAt(index, 2);
            numerologicTable.setOtherPostion(otherPosition);
            numerologicTable.setOtherToolTip(tokensStatisticsTable
                    .<String> getGenericValueAt(index, 0));
        } else {
            numerologicTable.setOtherPostion(-1);
        }
        numerologicTable.repaint();
    }
    
}
